//
//  CommunityController.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/11/21.
//  Copyright © 2017年 beisheng. All rights reserved.
//房屋车位出租信息3，邻里分享3，二手优品3，议事厅3，社区活动3，

#import "CommunityController.h"
#import "HomeCycleImageCell.h"
#import "NewCityDynamicHeader.h"
#import "SectionHeaderModel.h"
#import "MyWebViewController.h"
#import "NewCityHomeCell.h"
#import "LeaseHomeCell.h"
#import "SharDynamicHomeCell.h"
#import "GroupBuySuperCell.h"

#import "AllNewCityDynamicVC.h"
#import "AllComityActivisVC.h"
#import "AllCongressHallVC.h"
#import "AllSecondHandVC.h"
#import "AllNeighbourSharVC.h"
#import "AllHouseLeaseVC.h"
@interface CommunityController ()<DynamicHeaderDelegate>
/** <#note#> */
@property (nonatomic, strong) NSMutableArray *headerModels;

/** <#note#> */
@property (nonatomic, strong) NSMutableArray *dynamicModels;
@end

@implementation CommunityController


- (NSMutableArray *)dynamicModels{
    
    if (!_dynamicModels) {
        _dynamicModels = [NSMutableArray array];
        
        NewCityDynamicModel *model1 = [[NewCityDynamicModel alloc]init];
        model1.dynamicTitle = @"襄阳初雪: 你在老城区里寸步难行,我在浩然河畔美出诗意!";
        model1.dynamicTime = @"2016-11-25 18:52:00";
        model1.dynamicImage = @"http://mmbiz.qpic.cn/mmbiz_png/1YYHSkniajiaH1d0WxzpbwGfkPpu7x5dDw6H8K3rwFibZfy6qdibfPXfp9ibW6TDgSeSJQUgYMeqhiaw1krYchDLKZPQ/640?wx_fmt=png&wxfrom=5&wx_lazy=1";
        model1.dynamicDetailUrl = @"http://mp.weixin.qq.com/s/nn3hwmmLftYfvGoW1ibMFA";
        
        NewCityDynamicModel *model2 = [[NewCityDynamicModel alloc]init];
        model2.dynamicTitle = @"东津新区最新美图来袭，你关注的学校、医院、市民中心都在这，拿走不谢！";
        model2.dynamicTime = @"2017-6-27 18:07:00";
        model2.dynamicImage = @"https://mmbiz.qpic.cn/mmbiz_jpg/1YYHSkniajiaFcgrX2S7IWySTELFedbp7xlwVFEibf7DrGzf836m15Fy5NSsB8kms2pdR260HhS0s4LBLia2gydHaw/640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1";
        model2.dynamicDetailUrl = @"http://mp.weixin.qq.com/s/Gx4ZTSNrNsbQNYs4AzYLJg";
        
        NewCityDynamicModel *model3 = [[NewCityDynamicModel alloc]init];
        model3.dynamicTitle = @"市科技馆主体即将完工,'探索之眼'造型抢先看!!!";
        model3.dynamicTime = @"2016-11-18 18:07:00";
        model3.dynamicImage = @"http://mmbiz.qpic.cn/mmbiz_jpg/1YYHSkniajiaHyVwvISLNGu2Tw1fpp93x04aHGk2U8iasj7vZ3F9GibXARicELDchaoynO9hfjYPhPDk2cgDLUQLEyA/640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1";
        model3.dynamicDetailUrl = @"http://mp.weixin.qq.com/s/Q4fStCYW8jjjrs0oK8GmAQ";
        
        [_dynamicModels addObject:model2];
        [_dynamicModels addObject:model1];
        [_dynamicModels addObject:model3];
        
    }
    
    
    
    return _dynamicModels;
}

- (NSMutableArray *)headerModels{
    
    if (!_headerModels) {
        _headerModels = [NSMutableArray array];
        
        SectionHeaderModel *model0 = [[SectionHeaderModel alloc]init];
        model0.title = @"新城动态";
        model0.subTitle = @"一座城市的智慧未来";
        
        SectionHeaderModel *model1 = [[SectionHeaderModel alloc]init];
        model1.title = @"房屋车位出租";
//        model1.subTitle = @"2016-11-25 18:52:00";
       
        
        SectionHeaderModel *model2 = [[SectionHeaderModel alloc]init];
        model2.title = @"邻里分享";
//        model2.subTitle = @"2017-6-27 18:07:00";
      
        
        SectionHeaderModel *model3 = [[SectionHeaderModel alloc]init];
        model3.title = @"二手优品";
        model3.subTitle = @"淘二手,露两手";
        
        SectionHeaderModel *model4 = [[SectionHeaderModel alloc]init];
        model4.title = @"议事厅";
//        model4.subTitle = @"2016-11-18 18:07:00";
        
        SectionHeaderModel *model5 = [[SectionHeaderModel alloc]init];
        model5.title = @"社区活动";
//        model5.subTitle = @"2016-11-18 18:07:00";
        [_headerModels addObject:model0];
        [_headerModels addObject:model1];
        [_headerModels addObject:model2];
        [_headerModels addObject:model3];
        [_headerModels addObject:model4];
        [_headerModels addObject:model5];

    }
    
    
    
    return _headerModels;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    
 
    self.plainTableView.tableFooterView = [[UIView alloc]init];
    
    self.plainTableView.backgroundColor = [UIColor whiteColor];
    
    self.plainTableView.rowHeight = UITableViewAutomaticDimension;
    
    self.plainTableView.estimatedRowHeight = 100;
    
    [self.plainTableView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeCycleImageCell class]) bundle:nil] forCellReuseIdentifier:[HomeCycleImageCell identifierStr]];

    [self.plainTableView registerNib:[UINib nibWithNibName:NSStringFromClass([NewCityDynamicHeader class]) bundle:nil] forHeaderFooterViewReuseIdentifier:[NewCityDynamicHeader identifierStr]];
    
     [self.plainTableView registerNib:[UINib nibWithNibName:NSStringFromClass([NewCityHomeCell class]) bundle:nil] forCellReuseIdentifier:[NewCityHomeCell identifierStr]];
    
    
    [self.plainTableView registerNib:[UINib nibWithNibName:NSStringFromClass([LeaseHomeCell class]) bundle:nil] forCellReuseIdentifier:[LeaseHomeCell identifierStr]];
    
    [self.plainTableView registerNib:[UINib nibWithNibName:NSStringFromClass([SharDynamicHomeCell class]) bundle:nil] forCellReuseIdentifier:[SharDynamicHomeCell identifierStr]];
    
     [self.plainTableView registerNib:[UINib nibWithNibName:NSStringFromClass([GroupBuySuperCell class]) bundle:nil] forCellReuseIdentifier:[GroupBuySuperCell identifierStr]];
    
    // 设置标题
    if (@available(iOS 11.0, *)) {
        
        self.navigationController.navigationBar.prefersLargeTitles = YES;
        self.navigationItem.largeTitleDisplayMode =  UINavigationItemLargeTitleDisplayModeAlways;
        
    }
    
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.headerModels.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 3;
    } else if (section == 1){
       return 3;
    }else if (section == 2){
       return 3;
    }else if (section == 3){
       return 1;
    }else if (section == 4){
      return 1;
    }else{
       return 1;
    }
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        NewCityHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:[NewCityHomeCell identifierStr]];
        cell.model = self.dynamicModels[indexPath.row];
        return cell;
    } else if (indexPath.section == 1){
        LeaseHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:[LeaseHomeCell identifierStr]];
         return cell;
    }else if (indexPath.section == 2){
        SharDynamicHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:[SharDynamicHomeCell identifierStr]];
         return cell;
    }else if (indexPath.section == 3){
        GroupBuySuperCell *cell = [tableView dequeueReusableCellWithIdentifier:[GroupBuySuperCell identifierStr]];
         return cell;
    }else if (indexPath.section == 4){
        GroupBuySuperCell *cell = [tableView dequeueReusableCellWithIdentifier:[GroupBuySuperCell identifierStr]];
         return cell;
    }else{
        GroupBuySuperCell *cell = [tableView dequeueReusableCellWithIdentifier:[GroupBuySuperCell identifierStr]];
       return cell;
    }
    
    
   
    
   
    
   
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    

        return 44;
   
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    
    return 0.00001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
    NewCityDynamicHeader *temp = (NewCityDynamicHeader *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:[NewCityDynamicHeader identifierStr]];
    
    temp.delegate = self;
    
    temp.model = self.headerModels[section];
    
    
    return temp;
    
}




- (void)commityHeaderDidClickWith:(NSString *)title{
    
    if ([title isEqualToString:@"新城动态"]) {
        
        AllNewCityDynamicVC *tmep = [[AllNewCityDynamicVC alloc]init];
        
        
        [self.navigationController pushViewController:tmep animated:YES];
        
    } else if ([title isEqualToString:@"社区活动"]){
        AllComityActivisVC *tmep = [[AllComityActivisVC alloc]init];
        
        [self.navigationController pushViewController:tmep animated:YES];
    }else if ([title isEqualToString:@"议事厅"]){
        AllCongressHallVC *tmep = [[AllCongressHallVC alloc]init];
        
        [self.navigationController pushViewController:tmep animated:YES];
    }else if ([title isEqualToString:@"二手优品"]){
        AllSecondHandVC *tmep = [[AllSecondHandVC alloc]init];
        
        [self.navigationController pushViewController:tmep animated:YES];
    }else if ([title isEqualToString:@"邻里分享"]){
        AllNeighbourSharVC *tmep = [[AllNeighbourSharVC alloc]init];
        
        
        [self.navigationController pushViewController:tmep animated:YES];
    }else if ([title isEqualToString:@"房屋车位出租"]){
        AllHouseLeaseVC *tmep = [[AllHouseLeaseVC alloc]init];
        
        
        [self.navigationController pushViewController:tmep animated:YES];
    }
    
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    
    UIView *temp = [[UIView alloc]init];
    
    temp.backgroundColor = [UIColor whiteColor];
    
    return temp;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        NewCityDynamicModel *model = self.dynamicModels[indexPath.row];
        MyWebViewController *tempVC = [[MyWebViewController alloc]init];
        tempVC.urlString = model.dynamicDetailUrl;
        
        [self.navigationController pushViewController:tempVC animated:YES];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
